package com.jnevision.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

import com.crtland.landoss.LandOss;
import com.crtland.landoss.Oss;
import com.crtland.landoss.OssInfo;
import com.crtland.landoss.OssType;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;

@Configuration
public class JacksonConfig {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customJackson() {
        return jacksonObjectMapperBuilder -> {
            jacksonObjectMapperBuilder.serializationInclusion(JsonInclude.Include.NON_NULL);
            jacksonObjectMapperBuilder.failOnUnknownProperties(false);
            jacksonObjectMapperBuilder.propertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
        };
    }

    @Bean
    public OssInfo getOss(AliOssInfo aliConfig) {
        OssInfo ossInfo = new OssInfo();
        ossInfo.setAccessKeyId(aliConfig.getAccessKeyId());
        ossInfo.setAccessKeySecret(aliConfig.getAccessKeySecret());
        ossInfo.setBucketName(aliConfig.getBucketName());
        ossInfo.setEndpoint(aliConfig.getEndpoint());
        return ossInfo;
    }

    @Bean
    public Oss getLandOss(OssInfo info) {
        LandOss lo = new LandOss(redisTemplate);

        return lo.getLandOss(OssType.ALI, info);
    }
}
